<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>registry_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_tweak_registry_test.js.html">registry_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2013 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.tweak.RegistryTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.tweak.RegistryTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.asserts.AssertionError&#39;);
<a name="line19"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line20"></a>goog.require(&#39;goog.tweak&#39;);
<a name="line21"></a>/** @suppress {extraRequire} needed for createRegistryEntries. */
<a name="line22"></a>goog.require(&#39;goog.tweak.testhelpers&#39;);
<a name="line23"></a>
<a name="line24"></a>var registry;
<a name="line25"></a>
<a name="line26"></a>function setUp() {
<a name="line27"></a>  createRegistryEntries(&#39;&#39;);
<a name="line28"></a>  registry = goog.tweak.getRegistry();
<a name="line29"></a>}
<a name="line30"></a>
<a name="line31"></a>function tearDown() {
<a name="line32"></a>  goog.tweak.registry_ = null;
<a name="line33"></a>}
<a name="line34"></a>
<a name="line35"></a>function testGetBaseEntry() {
<a name="line36"></a>  // Initial values
<a name="line37"></a>  assertEquals(&#39;wrong bool1 object&#39;, boolEntry,
<a name="line38"></a>      registry.getBooleanSetting(&#39;Bool&#39;));
<a name="line39"></a>  assertEquals(&#39;wrong string object&#39;, strEntry,
<a name="line40"></a>      registry.getStringSetting(&#39;Str&#39;));
<a name="line41"></a>  assertEquals(&#39;wrong numeric object&#39;, numEntry,
<a name="line42"></a>      registry.getNumericSetting(&#39;Num&#39;));
<a name="line43"></a>  assertEquals(&#39;wrong button object&#39;, buttonEntry,
<a name="line44"></a>      registry.getEntry(&#39;Button&#39;));
<a name="line45"></a>  assertEquals(&#39;wrong button object&#39;, boolGroup,
<a name="line46"></a>      registry.getEntry(&#39;BoolGroup&#39;));
<a name="line47"></a>}
<a name="line48"></a>
<a name="line49"></a>function testInitializeFromQueryParams() {
<a name="line50"></a>  var testCase = 0;
<a name="line51"></a>  function assertQuery(queryStr, boolValue, enumValue, strValue, subBoolValue,
<a name="line52"></a>      subBoolValue2) {
<a name="line53"></a>    createRegistryEntries(queryStr);
<a name="line54"></a>    assertEquals(&#39;Wrong bool value for query: &#39; + queryStr, boolValue,
<a name="line55"></a>        boolEntry.getValue());
<a name="line56"></a>    assertEquals(&#39;Wrong enum value for query: &#39; + queryStr, enumValue,
<a name="line57"></a>        strEnumEntry.getValue());
<a name="line58"></a>    assertEquals(&#39;Wrong str value for query: &#39; + queryStr, strValue,
<a name="line59"></a>        strEntry.getValue());
<a name="line60"></a>    assertEquals(&#39;Wrong BoolOne value for query: &#39; + queryStr, subBoolValue,
<a name="line61"></a>        boolOneEntry.getValue());
<a name="line62"></a>    assertEquals(&#39;Wrong BoolTwo value for query: &#39; + queryStr, subBoolValue2,
<a name="line63"></a>        boolTwoEntry.getValue());
<a name="line64"></a>  }
<a name="line65"></a>  assertQuery(&#39;?dummy=1&amp;bool=&amp;enum=&amp;s=&#39;, false, &#39;&#39;, &#39;&#39;, false, true);
<a name="line66"></a>  assertQuery(&#39;?bool=0&amp;enum=A&amp;s=a&#39;, false, &#39;A&#39;, &#39;a&#39;, false, true);
<a name="line67"></a>  assertQuery(&#39;?bool=1&amp;enum=A&#39;, true, &#39;A&#39;, &#39;&#39;, false, true);
<a name="line68"></a>  assertQuery(&#39;?bool=true&amp;enum=B&amp;s=as+df&#39;, true, &#39;B&#39;, &#39;as df&#39;, false, true);
<a name="line69"></a>  assertQuery(&#39;?enum=C&#39;, false, &#39;C&#39;, &#39;&#39;, false, true);
<a name="line70"></a>  assertQuery(&#39;?enum=C&amp;boolgroup=-booltwo&#39;, false, &#39;C&#39;, &#39;&#39;, false, false);
<a name="line71"></a>  assertQuery(&#39;?enum=C&amp;boolgroup=b1,-booltwo&#39;, false, &#39;C&#39;, &#39;&#39;, true, false);
<a name="line72"></a>  assertQuery(&#39;?enum=C&amp;boolgroup=b1&#39;, false, &#39;C&#39;, &#39;&#39;, true, true);
<a name="line73"></a>  assertQuery(&#39;?s=a+b%20c%26&#39;, false, &#39;A&#39;, &#39;a b c&amp;&#39;, false, true);
<a name="line74"></a>}
<a name="line75"></a>
<a name="line76"></a>function testMakeUrlQuery() {
<a name="line77"></a>  assertEquals(&#39;All values are default.&#39;,
<a name="line78"></a>      &#39;&#39;, registry.makeUrlQuery(&#39;&#39;));
<a name="line79"></a>  assertEquals(&#39;All values are default - with existing params.&#39;,
<a name="line80"></a>      &#39;?super=pudu&#39;, registry.makeUrlQuery(&#39;?super=pudu&#39;));
<a name="line81"></a>
<a name="line82"></a>  boolEntry.setValue(true);
<a name="line83"></a>  numEnumEntry.setValue(2);
<a name="line84"></a>  strEntry.setValue(&#39;f o&amp;o&#39;);
<a name="line85"></a>  assertEquals(&#39;Wrong query string 1.&#39;,
<a name="line86"></a>      &#39;?bool=1&amp;enum2=2&amp;s=f+o%26o&#39;,
<a name="line87"></a>      registry.makeUrlQuery(&#39;?bool=1&#39;));
<a name="line88"></a>  assertEquals(&#39;Wrong query string 1 - with existing params.&#39;,
<a name="line89"></a>      &#39;?super=pudu&amp;bool=1&amp;enum2=2&amp;s=f+o%26o&#39;,
<a name="line90"></a>      registry.makeUrlQuery(&#39;?bool=0&amp;s=g&amp;super=pudu&#39;));
<a name="line91"></a>
<a name="line92"></a>  boolOneEntry.setValue(true);
<a name="line93"></a>  assertEquals(&#39;Wrong query string 2.&#39;,
<a name="line94"></a>      &#39;?bool=1&amp;boolgroup=B1&amp;enum2=2&amp;s=f+o%26o&#39;,
<a name="line95"></a>      registry.makeUrlQuery(&#39;&#39;));
<a name="line96"></a>
<a name="line97"></a>  boolTwoEntry.setValue(false);
<a name="line98"></a>  assertEquals(&#39;Wrong query string 3.&#39;,
<a name="line99"></a>      &#39;?bool=1&amp;boolgroup=B1,-booltwo&amp;enum2=2&amp;s=f+o%26o&#39;,
<a name="line100"></a>      registry.makeUrlQuery(&#39;&#39;));
<a name="line101"></a>}
<a name="line102"></a>
<a name="line103"></a>function testOverrideDefaultValue_calledBefore() {
<a name="line104"></a>  registry.overrideDefaultValue(&#39;b&#39;, false);
<a name="line105"></a>  registry.overrideDefaultValue(&#39;b&#39;, true);
<a name="line106"></a>  goog.tweak.registerBoolean(&#39;b&#39;, &#39;b desc&#39;);
<a name="line107"></a>  var bEntry = registry.getEntry(&#39;b&#39;);
<a name="line108"></a>  assertTrue(&#39;Default value should be true.&#39;, bEntry.getDefaultValue());
<a name="line109"></a>  assertTrue(&#39;Value should be true.&#39;, bEntry.getValue());
<a name="line110"></a>}
<a name="line111"></a>
<a name="line112"></a>function testOverrideDefaultValue_calledAfter() {
<a name="line113"></a>  var exception = assertThrows(&#39;Should assert.&#39;, function() {
<a name="line114"></a>    registry.overrideDefaultValue(&#39;Bool2&#39;, false);
<a name="line115"></a>  });
<a name="line116"></a>  assertTrue(&#39;Wrong exception&#39;,
<a name="line117"></a>      exception instanceof goog.asserts.AssertionError);
<a name="line118"></a>}
<a name="line119"></a>
<a name="line120"></a>function testCompilerOverrideDefaultValue() {
<a name="line121"></a>  createRegistryEntries(&#39;&#39;, { &#39;b&#39;: true });
<a name="line122"></a>  registry = goog.tweak.getRegistry();
<a name="line123"></a>  goog.tweak.registerBoolean(&#39;b&#39;, &#39;b desc&#39;);
<a name="line124"></a>  var bEntry = registry.getEntry(&#39;b&#39;);
<a name="line125"></a>  assertTrue(&#39;Default value should be true.&#39;, bEntry.getDefaultValue());
<a name="line126"></a>  assertTrue(&#39;Value should be true.&#39;, bEntry.getValue());
<a name="line127"></a>}
<a name="line128"></a>
<a name="line129"></a>function testCompilerAndJsOverrideDefaultValue() {
<a name="line130"></a>  createRegistryEntries(&#39;&#39;, { &#39;b&#39;: false });
<a name="line131"></a>  registry = goog.tweak.getRegistry();
<a name="line132"></a>  registry.overrideDefaultValue(&#39;b&#39;, true);
<a name="line133"></a>  goog.tweak.registerBoolean(&#39;b&#39;, &#39;b desc&#39;, true);
<a name="line134"></a>  var bEntry = registry.getEntry(&#39;b&#39;);
<a name="line135"></a>  assertFalse(&#39;Default value should be false.&#39;, bEntry.getDefaultValue());
<a name="line136"></a>  assertFalse(&#39;Value should be false.&#39;, bEntry.getValue());
<a name="line137"></a>}
</pre>


</body>
</html>
